import { RouterMount,createRouter,runtimeQuit } from './js_sdk/uni-simple-router';
import store from './store'
import Cache from './util/cache'
const scrollInfo = {};
let first = null;
// console.log('ROUTESROUTESROUTESROUTESROUTESROUTESROUTESROUTESROUTESROUTESROUTESROUTESROUTESROUTES',ROUTES);
const whiteList = ['login','joinName','index','weixinWeb','service']
const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: [
		...ROUTES,
		{
			path: '*',
			redirect: (to) => {
				return {
					name: '404'
				}
			}
		},
	]
});

router.beforeEach((to, from, next) => {
	let index = whiteList.findIndex((item) => to.path.includes(item))
    // console.log(store.getters.userInfo);
	if (index == -1 && !store.getters.token) {
		const pages = getCurrentPages();
		const route = pages[pages.length - 1].$page.fullPath;
		Cache.set('blackPath',route);
		next('/pages/login/login');
	} else if (index == -1 && !store.getters.userInfo && to.fullPath != '/pages/joinName/joinName') {
		next('/pages/joinName/joinName');
	} else {
		next();
	}
});

router.afterEach((to, from, next) => {
    
});


export {
	router,
	RouterMount
}
